﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>显示英文上、下午的时间</title>
    <script type="text/javascript">
        myDate = new Date();         //创建日期对象，获取当前日期
        //获取日期中的月、日、年
        document.write('<font size="2" face="Arial"><B>' + (myDate.getMonth() + 1) +"/"+myDate.getDate()+ "/"+myDate.getYear() + '</B></font><BR>');
        let Hours;
        let Mins;
        let Time;
        Hours = myDate.getHours();  //获取小时
        if (Hours >= 12) {
            Time = " P.M.";             //如果时间已经是下午（大于12点）则显示p.m.
        }
        else {
            Time = " A.M.";             //如果时间小于12点，则显示a.m.
        }
        if (Hours > 12) {           //如果小时数大于12，则减12，主要是为了显示上午和下午
            Hours -= 12;
        }
        if (Hours === 0) {           //0点时显示12点
            Hours = 12;
        }
        Mins = myDate.getMinutes(); //获取当前的分钟数
        if (Mins < 10) {
            Mins = "0" + Mins;          //如果分钟数小于10，则前面补0
        }
        document.write('<font size="2" face="Arial"><B>' + Hours + ":" + Mins + Time + '</B></font>');
    </script>
</head>
<body>

</body>
</html>